#  _*_ coding: utf-8 _*_
import os
from random import sample
from bbs.models import Board
from klein.settings import MEDIA_ROOT

__author__ = 'Beetle'

def create_id_code(size):
    str = ''.join(sample('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789', size))
    # print(str)
    return str

#对path进行处理
def mkdir(path):
    # 去除左右两边的空格
    path=path.strip()
    # 去除尾部 \符号
    path=path.rstrip("\\")
    path = MEDIA_ROOT+path
    print MEDIA_ROOT
    print path

    if not os.path.exists(path):
        os.makedirs(path)
    return path
#保存相关的文件
def save_file(path, file_name, data):
    if data == None:
        return

    path = mkdir(path)
    if(not path.endswith("/")):
        path=path+"/"
    file=open(path+file_name, "wb")
    file.write(data)
    file.flush()
    file.close()

# def init_data():
#     for temp in range(1,10):
#         board = Board(board_title=temp,board_desc_short=temp)
#         board.save()
#         print temp
#
#
# if __name__ == '__main__':
#     init_data()